import { useUserStoreHook } from '@/store/modules/user'
import { MsgType, type Msg, type TextBody } from './types'
export let ownerId = useUserStoreHook().id
export const refreshData = () => {
  ownerId = useUserStoreHook().id
}

export const getMsgShowContent = (msg: Msg<any>) => {
  switch (msg.type) {
    case MsgType.Text:
      return (msg.body as TextBody).content
    case MsgType.File:
      return '[文件]'
    case MsgType.Image:
      return '[图片]'
    case MsgType.Video:
      return '[视频]'
    case MsgType.Audio:
      return '[音频]'
    case MsgType.System:
      return '[系统消息]'
    default:
      return '[未知消息类型]'
  }
}

export const buildMsg = <T>(toId: number, type: MsgType, body: T) => {
  const msg: Msg<T> = {
    fromId: ownerId,
    toId,
    type,
    body,
    createdAt: new Date()
  }
  return msg
}
